const data = require('../../utils/data.js')
const util = require('../../utils/util.js')
Page({
  data: {
    hideModal: true, //模态框的状态  true-隐藏  false-显示
    animationData: {},//
    movies: [
      '../../image/img/goods-0.png',
      '../../image/img/goods-1.png',
    ],
    price:"￥49.00/箱",
    title:"",
    integral:'68',
    salesVolume:'3',
    numbers:'I40045',
    stock:'1000',
    typeclass:true,
    productImg: ["../../image/img/goods-1.png", "../../image/img/goods-0.png", "../../image/img/goods-1.png","../../image/img/goods-0.png"],
    parameterImg: ["../../image/img/goods-0.png", "../../image/img/goods-1.png","../../image/img/goods-0.png"],
    tips: '', 
    information: {},
    joinInformation:{
      btnName:"确定加入",
      unitPrice: "49.01",
      Price:"49.01",
      Number:1,
      Return:"BtnJoin"
    },
    purchaseInformation: {
      btnName: "确定",
      unitPrice: "49.01",
      Price: "49.01",
      Number: 1,
      Return: "BtnPurchase"
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: data.list_data[options.uid].name
    })
    this.setData({
      uid: options.uid,
      title: data.list_data[options.uid].name,
      tips:'6'
    })
  },
  setDetails(){
    wx.request({
      url: 'url',
      method: "GET",
      header: {
        'content-type': 'application/json'
      },
      success(res) {
        console.log("请求成功");

      },
      fail(res) {
        left.data.network = false;
      }
    })
  },
  btntype(e) { //点击修改内容
    var type = e.currentTarget.id == 1? true:false;
    this.setData({
      typeclass: type
    })
  },
  BtnService(){  // 客服
    console.log("客服")
  },
  BtnShare(){  // 分享
    console.log("分享")
  },
  BtnShoppingCart(){ //购物车
    wx.navigateTo({
      url: "../shoppingCart/shoppingCart"
    });
  },
  BtnPopup(e){//弹窗
    var data = e.currentTarget.id == "Join" ? this.data.joinInformation : this.data.purchaseInformation;
    this.setData({
      information: data
    })
    this.showModal();
  },
  
  minusCount(e) { // 减少数量
    var data = this.data.information
    var num = parseInt(data.Number);
    if (num <= 1) {
      return false;
    }
    data.Number = num = num - 1;
    data.Price = util.accMul(data.unitPrice, num);
    this.setData({
      information: data
    });
  },
  addCount(e) { //增加
    var data = this.data.information
    var num = parseInt(data.Number);
    data.Number = num = num + 1;
    data.Price = util.accMul(data.unitPrice, num);
    this.setData({
      information: data
    });
  },
  BtnJoin(){//加入购物车
    console.log("加入购物车")
  },
  BtnPurchase(){//立即购买
    console.log("立即购买")
    var left = this;
    wx.navigateTo({
      url: "../payment/payment?uid=" + left.data.uid+"&type="+true
    });
  },
  
  showModal: function () {// 显示遮罩层
      var that = this;
      that.setData({
        hideModal: false
      })
      this.animation = wx.createAnimation({
        duration: 400,//动画的持续时间 默认400ms   数值越大，动画越慢   数值越小，动画越快
        timingFunction: 'ease',//动画的效果 默认值是linear
      })
      setTimeout(function () {
        that.fadeIn();//调用显示动画
      }, 100)
  },
  hideModal: function () {// 隐藏遮罩层
      var that = this;
      this.animation = wx.createAnimation({
        duration: 400,//动画的持续时间 默认400ms   数值越大，动画越慢   数值越小，动画越快
        timingFunction: 'ease',//动画的效果 默认值是linear
      })
      that.fadeDown();//调用隐藏动画   
      setTimeout(function () {
        that.setData({
          hideModal: true
        })
      }, 450)//先执行下滑动画，再隐藏模块
  },
  fadeIn: function () {//显示动画
    this.animation.translateY(0).step()
    this.setData({
      animationData: this.animation.export()//动画实例的export方法导出动画数据传递给组件的animation属性
    })
  },
  fadeDown: function () {//隐藏动画
    this.animation.translateY(340).step()
    this.setData({
      animationData: this.animation.export(),
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})